package com.huawei.appgallery.foundation.account.bean;

import android.content.Intent;
import android.text.TextUtils;
import com.huawei.appgallery.jsonkit.api.JsonBean;
import com.huawei.appmarket.service.predownload.jobservice.UrgentUpdateJobService;
import o.ccm;
import o.Logger;
import o.ContentManager;
import o.eop;
import o.ll;

public class UserSession extends JsonBean {
    public static final int ADULT_AGE = 18;
    public static final int DEFAULT_AGE = 18;
    private static final String TAG = "UserSession";
    private static final UserSession USER_SESSION = new UserSession();
    private String accessToken_ = null;
    private String authAccount_ = null;
    private String deviceId_ = null;
    private String deviceType_ = null;
    private String headUrl_ = null;
    private long homeCountryTimestamp_ = 0;
    private String homeCountry_ = "";
    private boolean isLoginSuccessful_ = false;
    private boolean isMinor = false;
    private boolean isPushOpen = false;
    private String lastHomeCountry = "";
    private String nickname_ = null;
    private String serviceToken_ = null;
    private int status_ = 0;
    private int userAge_ = 18;
    private String userId_ = null;
    private String userName_ = null;

    public static UserSession getInstance() {
        return USER_SESSION;
    }

    public int getStatus() {
        return this.status_;
    }

    public void setStatus(int i) {
        this.status_ = i;
    }

    public boolean isLoginSuccessful() {
        return this.isLoginSuccessful_;
    }

    public void setLoginSuccessful(boolean z) {
        this.isLoginSuccessful_ = z;
    }

    public String getUserId() {
        return this.userId_;
    }

    public void setUserId(String str) {
        this.userId_ = str;
    }

    public String getServiceToken() {
        return this.serviceToken_;
    }

    public void setServiceToken(String str) {
        this.serviceToken_ = str;
    }

    public String getAuthAccount() {
        return this.authAccount_;
    }

    public void setAuthAccount(String str) {
        this.authAccount_ = str;
    }

    public String getUserName() {
        return this.userName_;
    }

    public void setUserName(String str) {
        this.userName_ = str;
    }

    public String getHeadUrl() {
        return this.headUrl_;
    }

    public void setHeadUrl(String str) {
        this.headUrl_ = str;
    }

    public String getDeviceType() {
        return this.deviceType_;
    }

    public void setDeviceType(String str) {
        this.deviceType_ = str;
    }

    public String getDeviceId() {
        return this.deviceId_;
    }

    public void setDeviceId(String str) {
        this.deviceId_ = str;
    }

    public String getHomeCountry() {
        return this.homeCountry_;
    }

    public void setHomeCountry(String str) {
        this.homeCountry_ = str;
        ll.ˏ(ContentManager.getInstant().getContext()).ˋ(new Intent("com.huawei.appmarket.oobe.ACTION_CHECK_SERVICE_ZONE"));
    }

    public void setHomeCountryTimestamp(String str) {
        setHomeCountry(str);
        this.homeCountryTimestamp_ = System.currentTimeMillis();
    }

    public int getUserAge() {
        return this.userAge_;
    }

    public void setUserAge(int i) {
        this.userAge_ = i;
    }

    public String getLastHomeCountry() {
        return this.lastHomeCountry;
    }

    public void setLastHomeCountry(String str) {
        this.lastHomeCountry = str;
    }

    public String getNickname() {
        return this.nickname_;
    }

    public void setNickname(String str) {
        this.nickname_ = str;
    }

    public String getAccessToken() {
        return this.accessToken_;
    }

    public void setAccessToken(String str) {
        this.accessToken_ = str;
    }

    public boolean loadCache(UserSession userSession) {
        if (this.status_ != 0) {
            return false;
        }
        Logger.ˎ(TAG, "loadCache");
        setLoginSuccessful(userSession.isLoginSuccessful_);
        setUserId(userSession.userId_);
        setServiceToken(userSession.serviceToken_);
        setAuthAccount(userSession.authAccount_);
        setUserName(userSession.userName_);
        setHeadUrl(userSession.headUrl_);
        setDeviceType(userSession.deviceType_);
        setDeviceId(userSession.deviceId_);
        setHomeCountry(userSession.homeCountry_);
        setStatus(1);
        setUserAge(userSession.userAge_);
        this.homeCountryTimestamp_ = userSession.homeCountryTimestamp_;
        return true;
    }

    public void refreshAccount(ccm o_ccm) {
        if (o_ccm != null) {
            setUserId(o_ccm.ˊ());
            setServiceToken(o_ccm.ˏ());
            setAuthAccount(o_ccm.ॱ());
            setUserName(o_ccm.ˋ());
            setDeviceType(o_ccm.ˎ());
            setDeviceId(o_ccm.ʽ());
            Object ᐝ = o_ccm.ᐝ();
            if (!TextUtils.isEmpty(ᐝ) && (System.currentTimeMillis() - this.homeCountryTimestamp_ > UrgentUpdateJobService.DEFAULT_JOB_PERIODIC || TextUtils.isEmpty(getHomeCountry()))) {
                setHomeCountry(ᐝ);
            }
            setLoginSuccessful(true);
            eop.ˎ(this);
            setStatus(4);
        }
    }

    public void reset() {
        Logger.ˎ(TAG, "UserSession reset.");
        setStatus(1);
    }

    public void clear() {
        Logger.ˎ(TAG, "UserSession clear.");
        setLoginSuccessful(false);
        setUserId(null);
        setServiceToken(null);
        setAuthAccount(null);
        setUserName(null);
        setHeadUrl(null);
        setDeviceType(null);
        setDeviceId(null);
        setUserAge(18);
        setHomeCountry(null);
        setAccessToken(null);
        setStatus(0);
    }

    public boolean isUserMinor() {
        return this.isLoginSuccessful_ && this.isMinor;
    }

    public void setUserMinor(boolean z) {
        this.isMinor = z;
    }

    public void setPushOpen(boolean z) {
        this.isPushOpen = z;
    }

    public boolean isUserPushOpen() {
        return this.isPushOpen;
    }
}
